home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / xloadct.pro < prev    next >
Text File  |  1997-07-08  |  18KB  |  549 lines

  1. ; $Id: xloadct.pro,v 1.20 1997/03/27 18:15:23 griz Exp $
  2. ;
  3. ; Copyright (c) 1991-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. PRO XLCT_PSAVE            ;Save/Restore our plotting state.
  7. ;  Swaps our state with the current state each time its called.
  8.  
  9. COMMON xloadct_com, r0, g0, b0, tfun, state, filename, cps, psave, pnt, $
  10.     top, bot, silent, chop, lock, g_lbl, vbot, vtop, g_slider, $
  11.     gamma, color, use_values, ncolors, cbot, siz, w_height, show_win
  12.  
  13. tmp = { xlct_psave, win: !d.window, x: !x.s, y: !y.s , xtype: !x.type, $
  14.                          ytype: !y.type, clip: !p.clip }
  15.  
  16. wset, psave.win
  17. !x.type = psave.xtype
  18. !y.type = psave.ytype
  19. !x.s = psave.x
  20. !y.s = psave.y
  21. !p.clip = psave.clip
  22. psave = tmp
  23. end
  24.  
  25. ; Redraw the ramp image.
  26. PRO xlct_show
  27. COMMON xloadct_com, r0, g0, b0, tfun, state, filename, cps, psave, pnt, $
  28.     top, bot, silent, chop, lock, g_lbl, vbot, vtop, g_slider, $
  29.     gamma, color, use_values, ncolors, cbot, siz, w_height, show_win
  30.  
  31.     cur_win = !D.WINDOW
  32.     WSET, show_win
  33.     TV, BYTE((FLOAT(ncolors)*FINDGEN(siz)/FLOAT(siz-1)) # $
  34.         REPLICATE(1, w_height)) + BYTE(cbot)
  35.  
  36.     WSET, cur_win
  37. END
  38.  
  39. PRO xlct_draw_cps, i, c
  40. COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  41. COMMON xloadct_com, r0, g0, b0, tfun, state, filename, cps, psave, pnt, $
  42.     top, bot, silent, chop, lock, g_lbl, vbot, vtop, g_slider, $
  43.     gamma, color, use_values, ncolors, cbot
  44.  
  45. tc = color
  46. if n_elements(c) gt 0 then begin
  47.     tc = c
  48.     if c ne 0 then color = c
  49.     endif
  50.  
  51. if i[0] eq -1 then j = indgen(n_elements(cps)) else j = i
  52.  
  53. plots, cps[j], tfun[j], /noclip, color = tc
  54. plots, cps[j], tfun[j], /noclip, psym=6, color = tc
  55. end
  56.  
  57. PRO xlct_transfer, UPDATE=update
  58. COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  59. COMMON xloadct_com, r0, g0, b0, tfun, state, filename, cps, psave, pnt, $
  60.     top, bot, silent, chop, lock, g_lbl, vbot, vtop, g_slider, $
  61.     gamma, color, use_values, ncolors, cbot
  62.  
  63. l = lonarr(ncolors)        ;Subscripts
  64. m = n_elements(cps)
  65. for i=0, m-2 do begin
  66.     n = cps[i+1]-cps[i]        ;Interval
  67.     b = (tfun[i+1]-tfun[i])/float(n)
  68.     l[cps[i]] = findgen(n) * b + (tfun[i] + cbot)
  69.     endfor
  70. l[ncolors-1] = tfun[m-1]        ;Last point
  71. if use_values then begin
  72.   r_curr[cbot] = (r = l[r_orig])
  73.   g_curr[cbot] = (g = l[g_orig])
  74.   b_curr[cbot] = (b = l[b_orig])
  75. endif else begin
  76.   r_curr[cbot] = (r = r_orig[l])
  77.   g_curr[cbot] = (g = g_orig[l])
  78.   b_curr[cbot] = (b = b_orig[l])
  79. endelse
  80.  
  81. tvlct, r,g,b, cbot
  82. if (keyword_set( update )) then $
  83.   xlct_show
  84. end
  85.  
  86. PRO xloadct_event, event
  87. COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  88. COMMON xloadct_com, r0, g0, b0, tfun, state, filename, cps, psave, pnt, $
  89.     top, bot, silent, chop, lock, g_lbl, vbot, vtop, g_slider, $
  90.     gamma, color, use_values, ncolors, cbot, siz, w_height, show_win
  91.  
  92.  
  93. IF event.id eq state.draw THEN BEGIN    ;** PROCESS DRAWABLE EVENTS **
  94.     if event.press ne 0 then begin        ;Pressed button?
  95.         dmin = 1.0e8        ;Find closest control pnt
  96.         xlct_psave        ;Remove old
  97.         p = convert_coord(event.x, event.y, /TO_DATA, /DEVICE)
  98.         xlct_psave        ;Restore old
  99.         x = fix(p[0])
  100.         y = fix(p[1])
  101.         for i=0, n_elements(cps)-1 do begin
  102.             d = (p[0]-cps[i])^2 + (p[1]-tfun[i])^2  ; dist ^ 2
  103.             if d lt dmin then begin
  104.                 dmin = d
  105.                 pnt = i
  106.                 endif
  107.             endfor
  108.         return
  109.         endif
  110.     if event.release ne 0 then begin    ;Released button?
  111.         pnt = -1
  112.                 xlct_transfer, /update
  113.         return
  114.         endif
  115.     if pnt lt 0 then return            ;Don't care here...
  116.  
  117.     xlct_psave                ;Remove old
  118.     p = convert_coord(event.x, event.y, /TO_DATA, /DEVICE)    ;Coord of mouse
  119.     n = ncolors -1        ;Into range....
  120.     m = n_elements(cps)-1
  121.     x = fix(p[0]) > 0 < n
  122.     if pnt eq 0 then x = 0 else $        ;1st & last are fixed
  123.     if pnt eq m then x = n else $
  124.     x = x > (cps[pnt-1] + 1) < (cps[pnt+1]-1)  ;Others must be between
  125.  
  126.     if pnt eq 0 then xlct_draw_cps, [0, 1],0 $  ;Erase old segment
  127.     else if pnt eq m then xlct_draw_cps, [m-1, m],0 $
  128.     else xlct_draw_cps, [pnt-1, pnt, pnt+1],0
  129.     cps[pnt] = x
  130.     tfun[pnt] = fix(p[1]) > 0 < n
  131.     xlct_transfer
  132.  
  133.     b = r_curr * .3 + g_curr * .586 + b_curr * .114 ;Ntsc colors
  134.     c = max(abs(b-b[cbot]), j)  ; *** J is color index furthest from 0
  135.  
  136.     if pnt eq 0 then xlct_draw_cps, [0, 1], j $
  137.     else if pnt eq m then xlct_draw_cps, [m-1, m], j $
  138.     else xlct_draw_cps, [pnt-1, pnt, pnt+1], j
  139.  
  140.     xlct_psave        ;Remove old
  141.     return
  142.     ENDIF
  143.  
  144. WIDGET_CONTROL, event.id, GET_UVALUE = eventval
  145.  
  146. abstop = NCOLORS -1
  147.  
  148. if event.id eq state.name_list then begin
  149.     LOADCT, silent=silent, event.index, FILE=filename, NCOLORS=ncolors, $
  150.         BOTTOM=cbot
  151.     goto, set_gamma
  152.     ENDIF
  153.  
  154. CASE eventval OF
  155.     "TOP":    BEGIN
  156.         WIDGET_CONTROL, top, GET_VALUE = vtop
  157.                 if lock ne 0 then begin
  158.                         vbot = (vtop - lock) > 0 < 100
  159.                         widget_control, bot, SET_VALUE=vbot
  160.                         endif
  161.                 GOTO, set_gamma
  162.               END
  163.  
  164.     "BOTTOM": BEGIN
  165.         WIDGET_CONTROL, bot, GET_value = vbot
  166.                 if lock ne 0 then begin
  167.                         vtop = (vbot + lock) > 0 < 100
  168.                         widget_control, top, SET_VALUE=vtop
  169.                         ENDIF
  170.    set_gamma:
  171.     if use_values then nc = 256 else nc = ncolors
  172.     s = (nc-1)/100.
  173.     x0 = vbot * s
  174.     x1 = vtop * s
  175.     if x0 ne x1 then s = (nc-1.0)/(x1 - x0) else s = 1.0
  176.     int = -s * x0
  177.     if gamma eq 1.0 then s = round(findgen(nc) * s + int > 0.0) $
  178.     else s = ((findgen(nc) * (s/nc) + (int/nc) > 0.0) ^ gamma) * nc
  179.     if chop ne 0 then begin
  180.         too_high = where(s ge nc, n)
  181.         if n gt 0 then s[too_high] = 0L
  182.         endif
  183.     if use_values then begin
  184.         s = s < 255L
  185.         l = lindgen(ncolors) + cbot
  186.         r_curr[cbot] = (r = s[r_orig[l]])
  187.         g_curr[cbot] = (g = s[g_orig[l]])
  188.         b_curr[cbot] = (b = s[b_orig[l]])
  189.     endif else begin
  190.         s = s + cbot
  191.         r_curr[cbot] = (r = r_orig[s])
  192.         g_curr[cbot] = (g = g_orig[s])
  193.         b_curr[cbot] = (b = b_orig[s])
  194.      endelse
  195.     tvlct, r,g,b, cbot
  196.         xlct_show
  197.     ENDCASE
  198.  
  199.     "GAMMA": BEGIN
  200.                 WIDGET_CONTROL, g_slider, GET_VALUE = gamma
  201.                 gamma = 10^((gamma/50.) - 1)
  202.                 WIDGET_CONTROL, g_lbl, SET_VALUE = $
  203.             STRING(gamma, format='(f6.3)')
  204.         goto, set_gamma
  205.              ENDCASE
  206.  
  207.     "GANG" : IF event.value eq 0 then lock = 0 else lock = vtop - vbot
  208.  
  209.     "CHOP" : BEGIN
  210.         chop = event.value
  211.         goto, set_gamma         ;And redraw
  212.         ENDCASE
  213.  
  214.     "VALUES": BEGIN
  215.     use_values = event.value
  216.     ENDCASE
  217.  
  218.     "HELP" : XDisplayFile, FILEPATH("xloadct.txt", subdir=['help', 'widget']), $
  219.                 TITLE = "Xloadct Help", $
  220.                 GROUP = event.top, $
  221.                 WIDTH = 55, $
  222.                 HEIGHT = 16
  223.  
  224.     "RESTORE" : BEGIN                   ;Restore the original tables
  225.         r_curr = (r_orig = r0)
  226.         g_curr = (g_orig = g0)
  227.         b_curr = (b_orig = b0)
  228.     tvlct, r_curr, g_curr, b_curr
  229.         xlct_show
  230.         ENDCASE
  231.  
  232.     "OVERWRITE" : BEGIN                 ;overwrite original tables
  233.     r0 = (r_orig = r_curr)
  234.     g0 = (g_orig = g_curr)
  235.     b0 = (b_orig = b_curr)
  236.     reset_all:
  237.         WIDGET_CONTROL, top, SET_VALUE = 100
  238.         WIDGET_CONTROL, bot, SET_VALUE = 0
  239.         WIDGET_CONTROL, g_slider, SET_VALUE = 50
  240.     vbot = 0
  241.     vtop = 100
  242.     gamma = 1.0
  243.     GOTO, set_gamma
  244.     ENDCASE
  245.  
  246.     "REVERSE" : BEGIN                   ;Reverse the table
  247.     l = lindgen(ncolors) + cbot
  248.         r_orig[cbot] = reverse(r_orig[l])
  249.         g_orig[cbot] = reverse(g_orig[l])
  250.         b_orig[cbot] = reverse(b_orig[l])
  251.         goto, set_gamma                 ;And redraw
  252.         ENDCASE
  253.  
  254.     "DONE": BEGIN
  255.         WIDGET_CONTROL, event.top, /DESTROY
  256.         r0 = 0 & g0 = 0 & b0 = 0  ;Free common
  257.         ENDCASE
  258.  
  259.     "NEWBASE": BEGIN
  260.     mode = event.value
  261.     b = ([0, 0, 1])[mode]        ;Top base to map: 0 or 1.
  262.     for i=0,1 do WIDGET_CONTROL, state.bases[i], MAP=i eq b
  263.     if b eq 0 then begin        ;table or option mode?
  264.        b = ([2,3,0])[mode]        ;bottom base to map (mode eq 0 or 1)
  265.        for i=2,3 do WIDGET_CONTROL, state.bases[i], MAP=i eq b
  266.        endif
  267.     if mode eq 2 then begin
  268.         reset_all = 1
  269.         xlct_psave            ;Save old state
  270.         plot, [0, ncolors-1], [0, ncolors-1], xstyle=3, $
  271.         ystyle=3, xmargin = [1,1], ymargin=[1,1], ticklen = -0.03, $
  272.         /NODATA, $
  273.         xtickname = replicate(' ', 10), ytickname = replicate(' ', 10)
  274.         goto, interp_cps
  275.         endif
  276.     
  277.     ENDCASE
  278.  
  279.     "TFUNR": BEGIN
  280.      reset_tfun:
  281.     xlct_psave
  282.     xlct_draw_cps, -1, 0    ;Erase all
  283.     tfun = cps        ;Linear ramp
  284.     goto, interp_cps
  285.     ENDCASE
  286.  
  287.     "REMCP": BEGIN
  288.     n = n_elements(cps)
  289.     if n gt 2 then begin
  290.       xlct_psave
  291.       xlct_draw_cps, -1, 0
  292.       igap = 0
  293.       for i=0, n-2 do $
  294.         if (cps[i+1] - cps[i]) lt (cps[igap+1]-cps[igap]) then $
  295.             igap = i
  296.       keep = where(indgen(n) ne (igap > 1))
  297.       cps = cps[keep]
  298.       tfun = tfun[keep]
  299.       goto, interp_cps
  300.       ENDIF
  301.     ENDCASE
  302.     "ADDCP": BEGIN
  303.     xlct_psave
  304.     xlct_draw_cps, -1, 0
  305.     igap = 0            ;Find largest gap
  306.     for i=0, n_elements(cps)-2 do $
  307.         if (cps[i+1] - cps[i]) gt (cps[igap+1]-cps[igap]) then $
  308.             igap = i
  309.     cps = [ cps[0:igap], (cps[igap]+cps[igap+1])/2, cps[igap+1:*]]
  310.     tfun = [ tfun[0:igap], (tfun[igap]+tfun[igap+1])/2, tfun[igap+1:*]]
  311.       interp_cps:  xlct_draw_cps, -1  ;Redraw new
  312.     xlct_transfer, /update
  313.     xlct_psave        ;Restore old points
  314.     if n_elements(reset_all) then goto, reset_all
  315.     ENDCASE
  316. ENDCASE
  317.  
  318. END
  319.  
  320.  
  321. ;+
  322. ; NAME:
  323. ;       XLOADCT
  324. ; PURPOSE:
  325. ;       A graphical interface to the LOADCT user library procedure.
  326. ;       XLOADCT displays the current color map and provides
  327. ;       an array of buttons, one per availible predefined color
  328. ;       table. Using the mouse to press these buttons causes
  329. ;       the corresponding color map to be loaded.
  330. ; CATEGORY:
  331. ;       Widgets
  332. ; CALLING SEQUENCE:
  333. ;       XLOADCT
  334. ; INPUTS:
  335. ;       None.
  336. ; KEYWORDS:
  337. ;    FILE:    If this keyword is set, the file by the given name is used
  338. ;        instead of the file colors1.tbl in the IDL directory.  This
  339. ;        allows multiple IDL users to have their own color table file.
  340. ;       GROUP = The widget ID of the widget that calls XLoadct.  When 
  341. ;               this ID is specified, a death of the caller results in a 
  342. ;               death of XLoadct
  343. ;    NCOLORS = number of colors to use.  Use color indices from BOTTOM
  344. ;        to the smaller of !D.TABLE_SIZE-1 and NCOLORS-1.
  345. ;        Default = !D.TABLE_SIZE = all available colors.
  346. ;    BOTTOM = first color index to use. Use color indices from BOTTOM to
  347. ;        BOTTOM+NCOLORS-1.  Default = 0.
  348. ;       SILENT - Normally, no informational message is printed when
  349. ;               a color map is loaded. If this keyword is present and
  350. ;               zero, this message is printed.
  351. ;    USE_CURRENT: If set, use the current color tables, regardless of
  352. ;        the contents of the COMMON block COLORS.
  353. ;       MODAL:  If set, then XLOADCT runs in "modal" mode, meaning that
  354. ;               all other widgets are blocked until the user quits XLOADCT.
  355. ;               A group leader must be specified (via the GROUP keyword)
  356. ;               for the MODAL keyword to have any effect.   The default
  357. ;               is to not run in modal mode.
  358. ;
  359. ; OUTPUTS:
  360. ;       None.
  361. ; COMMON BLOCKS:
  362. ;       None.
  363. ; SIDE EFFECTS:
  364. ;       One of the predefined color maps may be loaded.
  365. ; RESTRICTIONS:
  366. ;       This routine uses the LOADCT user library procedure to
  367. ;       do the actual work.
  368. ; MODIFICATION HISTORY:
  369. ;       24, August, 1990, Written by AB, RSI.
  370. ;       March 1, 1992  Mark Rivers added Reverse Table to options menu.
  371. ;    7/92, DMS, Added new color tables (allows more than 16).
  372. ;    9/92, ACY, Add FILE keyword.
  373. ;    10/1/96, AB, Removed the PICK_ONE keyword. It was broken for 4 years
  374. ;        without anyone noticing, and the idea doesn't really fit
  375. ;        XLOADCT anymore.
  376. ;       1/10/97, DJC - Fixed color bar display bug, and added "MODAL" keyword.
  377. ;    1/13/96, AB, Improved the saving and restoring of the current
  378. ;        graphics window to prevent other applications from drawing
  379. ;        on this applications windows.
  380. ;       1/17/97, DJC - Moved group_leader keyword from "XManager" to
  381. ;               "WIDGET_BASE".   Added check to ignore "MODAL" keyword
  382. ;               if a group leader is not specified.
  383. ;-
  384.  
  385. PRO XLoadct, SILENT=silent_f, GROUP=group, FILE=file, $
  386.     USE_CURRENT=use_current, NCOLORS = nc, BOTTOM=bottom, $
  387.         MODAL=modal
  388.  
  389. COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  390. COMMON xloadct_com, r0, g0, b0, tfun, state, filename, cps, psave, pnt, $
  391.     top, bot, silent, chop, lock, g_lbl, vbot, vtop, g_slider, $
  392.     gamma, color, use_values, ncolors, cbot, siz, w_height, show_win
  393.  
  394.  
  395. IF(XRegistered("xloadct") NE 0) THEN return
  396.  
  397. values_button = lonarr(2)
  398.  
  399. IF KEYWORD_SET(SILENT_f) THEN silent = SILENT_F ELSE silent = 1
  400.  
  401. IF N_ELEMENTS(file) GT 0 THEN filename = file
  402.  
  403. siz = 256            ;Basic width of tool
  404. names = 0
  405. LOADCT, GET_NAMES = names, FILE = file    ;Get table names
  406. w_height = 50                   ;Height of ramp
  407. cur_win = !D.WINDOW
  408. lock = 0
  409. chop = 0
  410. vbot = 0
  411. vtop = 100
  412. gamma = 1.0
  413. use_values=0
  414.  
  415.  
  416. ; Bases:
  417. ;  0 = slider base  (stretch bottom, stretch top, gamma)
  418. ;  1 = transfer function drawable + buttons
  419. ;  2 = color table list
  420. ;  3 = options base  (sliders. top, stretch)
  421.  
  422. state = { bases: lonarr(4), draw: 0L, name_list: 0L }
  423.  
  424. ; DJC - Added modal keyword.
  425. ; Moved "group_leader" keyword from XMANAGER to WIDGET_BASE.
  426. ; Ignore modal keyword if a group leader is not supplied.
  427. if (N_ELEMENTS(group) GT 0L) then $
  428.    base = WIDGET_BASE(TITLE="XLoadct", /COLUMN, GROUP_LEADER=group, $
  429.                       MODAL=KEYWORD_SET(modal)) $
  430. else $
  431.    base = WIDGET_BASE(TITLE="XLoadct", /COLUMN)
  432.  
  433.  
  434. ; Setting the managed attribute indicates our intention to put this app
  435. ; under the control of XMANAGER, and prevents our draw widgets from
  436. ; becoming candidates for becoming the default window on WSET, -1. XMANAGER
  437. ; sets this, but doing it here prevents our own WSETs at startup from
  438. ; having that problem.
  439. WIDGET_CONTROL, /MANAGED, base
  440.  
  441.  
  442. show = WIDGET_DRAW(base, YSIZE=w_height, XSIZE=siz, /FRAME, RETAIN = 2)
  443. junk = WIDGET_BASE(base, /ROW)
  444. done = WIDGET_BUTTON(junk, VALUE=' Done ', UVALUE = "DONE")
  445. junk1 = WIDGET_BUTTON(junk, VALUE=' Help ', UVALUE = "HELP")
  446.  
  447. junk = CW_BGROUP(base, /ROW, /EXCLUSIVE, /NO_REL, $
  448.     ['Tables', 'Options', 'Function'], $
  449.     UVALUE='NEWBASE', SET_VALUE=0)
  450.  
  451. junk = widget_base(base)
  452. for i=0,1 do state.bases[i] = WIDGET_BASE(junk, /COLUMN)
  453.  
  454. sbase=WIDGET_BASE(state.bases[0], /COLUMN)
  455. bot = WIDGET_SLIDER(sbase, TITLE = "Stretch Bottom", MINIMUM = 0, $
  456.       MAXIMUM = 100, VALUE = 0, /DRAG, UVALUE = "BOTTOM", xsize=siz)
  457. top = WIDGET_SLIDER(sbase, TITLE = "Stretch Top", MINIMUM = 0, $
  458.       MAXIMUM = 100, VALUE = 100, /DRAG, UVALUE = "TOP", xsize=siz)
  459. g_lbl = WIDGET_LABEL(sbase, VALUE = STRING(1.0))
  460. g_slider = WIDGET_slider(sbase, TITLE = "Gamma Correction", $
  461.       MINIMUM = 0, MAXIMUM = 100, VALUE = 50, UVALUE = "GAMMA", $
  462.       /SUPPRESS_VALUE, /DRAG, xsize=siz)
  463.  
  464. junk = WIDGET_BASE(sbase)
  465. for i=2,3 do state.bases[i] = WIDGET_BASE(junk, /COLUMN)
  466. DEVICE, GET_SCREEN = junk
  467. if junk[1] le 768 then junk = 8 else junk = 16
  468. state.name_list = WIDGET_LIST(state.bases[2], VALUE = names, ysize = junk)
  469.  
  470.  
  471. ;        Drawable for transfer function
  472.  
  473. junk = WIDGET_BASE(state.bases[1], /COLUMN, /FRAME)
  474. junk1 = WIDGET_BUTTON(junk, VALUE = 'Reset Transfer Function', $
  475.     UVALUE='TFUNR')
  476. junk1 = WIDGET_BUTTON(junk, VALUE='Add Control Point', UVALUE='ADDCP')
  477. junk1 = WIDGET_BUTTON(junk, VALUE='Remove Control Point', UVALUE='REMCP')
  478.  
  479. state.draw = WIDGET_DRAW(state.bases[1], xsize = siz, ysize = siz, $
  480.     /BUTTON_EVENTS, /MOTION_EVENTS)
  481.  
  482.  
  483.  opt_id = state.bases[3]
  484.  junk = CW_BGROUP(opt_id, /ROW, LABEL_LEFT='Sliders:', /EXCLUSIVE, /NO_REL, $
  485.         ['Independent', 'Gang'], UVALUE='GANG', SET_VALUE=lock)
  486.  junk = CW_BGROUP(opt_id, /ROW, LABEL_LEFT = 'Top:',  /EXCLUSIVE, /NO_REL, $
  487.         ['Clip', 'Chop'], SET_VALUE=chop, UVALUE='CHOP')
  488.  junk = CW_BGROUP(opt_id, /ROW, LABEL_LEFT='Stretch:',  /EXCLUSIVE, /NO_REL, $
  489.         ['Indices', 'Intensity'], UVALUE='VALUES', $
  490.         SET_VALUE=use_values)
  491.  junk = WIDGET_BUTTON(opt_id, VALUE='Reverse Table', $
  492.                 UVALUE="REVERSE", /NO_REL)
  493.  junk = WIDGET_BUTTON(opt_id, VALUE='REPLACE Original Table', $
  494.         UVALUE = "OVERWRITE", /NO_REL)
  495.  junk = WIDGET_BUTTON(opt_id, VALUE='RESTORE Original Table', $
  496.                 UVALUE="RESTORE", /NO_REL)
  497.  
  498. WIDGET_CONTROL, state.bases[1], MAP=0    ;Tfun is not visible
  499. WIDGET_CONTROL, state.bases[3], MAP=0    ;options are not visible
  500.  
  501. WIDGET_CONTROL, base, /REALIZE
  502. WIDGET_CONTROL, state.draw, GET_VALUE=tmp
  503.  
  504. if n_elements(bottom) gt 0 then cbot = bottom else cbot = 0
  505. ncolors = !d.table_size - cbot
  506. if n_elements(nc) gt 0 then ncolors = ncolors < nc
  507. if ncolors le 0 then message,'Number of colors is 0 or negative'
  508.  
  509. psave = { xlct_psave, win: !d.window, x: !x.s, y: !y.s , xtype: !x.type, $
  510.                       ytype: !y.type, clip: !p.clip }
  511. ;Our initial state
  512. wset, tmp            ;Initial graph
  513. xlct_psave        ;Save original scaling & window
  514. plot, [0, ncolors-1], [0, ncolors-1], xstyle=3, ystyle=3, $
  515.     xmargin = [1,1], ymargin=[1,1], ticklen = -0.03, /NODATA
  516. xlct_psave        ;Restore original scaling & window
  517.  
  518.             ;If no common, use current colors
  519. IF KEYWORD_SET(use_current) or N_ELEMENTS(r_orig) LE 0 THEN BEGIN
  520.     TVLCT, r_orig, g_orig, b_orig, /GET
  521.     r_curr = r_orig
  522.     b_curr = b_orig
  523.     g_curr = g_orig
  524.     ENDIF
  525.  
  526. r0 = r_curr             ;Save original colors
  527. g0 = g_curr
  528. b0 = b_curr
  529. color = ncolors + cbot -1
  530. cps = [0, ncolors-1]
  531. tfun = cps
  532. pnt = -1
  533.  
  534. WIDGET_CONTROL, show, GET_VALUE=show_win
  535. WSET, show_win
  536.  
  537. ; DJC - fixed color bar display bug.
  538.  
  539. ;TVSCL, BYTSCL(INDGEN(siz) # REPLICATE(1, w_height), top = ncolors-1)
  540. TV, BYTE((FLOAT(ncolors)*FINDGEN(siz)/FLOAT(siz-1)) # $
  541.        REPLICATE(1, w_height)) + BYTE(cbot)
  542.  
  543. WSET, cur_win
  544.  
  545. ; DJC - moved GROUP_LEADER keyword to WIDGET_BASE.
  546. XManager, "xloadct", base, /NO_BLOCK, MODAL=KEYWORD_SET(modal)
  547.  
  548. END
  549.